package com.bnz.config;

import com.bnz.properties.HelloProperties;
import com.bnz.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类
 */

@EnableConfigurationProperties({HelloProperties.class}) // 相当于是把HelloProperties放进spring容器中
@Configuration // 相当于：applicationContext.xml文件
@ConditionalOnClass(HelloService.class) // 检验当前系统中是否有HelloService这个类,这个是一个条件注解
public class HelloServiceAutoConfiguration {

    // 注入HelloProperties
//    @Autowired
//    private HelloService helloService;

    @Bean // 相当于是吧此方法名作为bean放进spring容器，可以直接拿(helloService)
    public HelloService helloService(HelloService helloService){ // 与上方@Autowired一样
        // 1、定义一个HelloService
        HelloService service = new HelloService();
        service.setName(helloService.getName());
        service.setAge(helloService.getAge());
        return service;
    }

}
